<template>
    <div class="box">
        <van-nav-bar :title="housetpye" left-text="返回" left-arrow @click-left="onClickLeft" />
        <nav>
            <div class="left">
                <van-field v-model="fieldValue" is-link readonly placeholder="北京" @click="show = true" />
                <van-popup v-model:show="show" round position="bottom">
                    <van-cascader v-model="cascaderValue" title="请选择所在地区" :options="options" @close="show = false"
                        @finish="onFinish" />
                </van-popup>
            </div>
            <div class="con">
                <van-field v-model="value1" placeholder="显示图标">
                    <template #right-icon>
                        <van-icon name="search" @click="Search" />
                    </template>
                </van-field>
            </div>
            <div class="right">
                <span>地图选点</span>
            </div>
        </nav>
        <header>
            <div class="Top-con">
                <div class="Top-con-item" v-for="(item, index) in fangTab" :key="index" @click="TabHouse(item, index)">
                    <img :src="item.img" mode="" />
                    <span :class="index === TabIndex ? 'on' : ''" style="font-size: 30rpx;">{{ item.text }}</span>
                </div>
            </div>
        </header>
        <Tab></Tab>
        <div class="box-con">
            <div class="con" v-if="dataList.newdatalist.length">
                <div class="con-item" v-for="(item, index) in dataList.newdatalist" :key="index">
                    <div class="con-item-left">
                        <img :src="item.img" class="img" />
                    </div>
                    <div class="con-item-right">
                        <div class="title">{{ item.name }}</div>
                        <div class="pingmi">{{ item.ll }}平/{{ item.house_type }}/{{ item.resident }}</div>
                        <div class="jiage"><text class="price">{{ item.price }}万</text><text class="mi">{{ item.extent
                        }}万元/㎡</text>
                        </div>
                        <div class="type">{{ item.renovation }}</div>
                    </div>
                </div>
            </div>
            <div v-else class="null">
                <img src="http://10.31.71.52:7002/public/static/Xinfang/暂无数据.png" />
                <span>房源信息正在补充中</span>
            </div>
        </div>
    </div>
</template>
  
<script setup>

import { ref, reactive, toRefs } from 'vue';
import { useCascaderAreaData } from '@vant/area-data';
import request from '../../utils/request';
import Tab from '../Tab/Tab.vue';

// fangTab tab切换数据
const { fangTab, finclonedatalist, PATH, newdataList,housetpye } = defineProps(['fangTab', 'finclonedatalist', 'PATH', 'newdataList','housetpye']);
const emit = defineEmits(['GET_Path']);

(() => {
    request.get(PATH).then((res) => {
        if (res.data.code === 1) {
            dataList.newdatalist = res.data.data;
            clonedatalist.newdatalist = res.data.data;
            towclonedatalist.newdatalist = res.data.data;
        }
    })
})()

// 页面渲染数据
const dataList = reactive({
    newdatalist: []
});
// 页面渲染数据
const clonedatalist = reactive({
    newdatalist: []
});
const towclonedatalist = reactive({
    newdatalist: []
});

const onClickLeft = () => history.back();

// 头部tab切换的高亮下标
const TabIndex = ref(false);

// 头部tab点击事件
const TabHouse = async (item, index) => {
    TabIndex.value = index;
    const items = [];
    const str = item.text.slice(1);
    towclonedatalist.newdatalist.forEach((obj) => {
        if (obj.building_type.includes(str)) {
            items.push(obj);
        }
    })
    if (items.length) {
        dataList.newdatalist = items;
    } else {
        dataList.newdatalist = []
    }
};

// 地址三级联动
const show = ref(false);
const fieldValue = ref('全部');
const cascaderValue = ref('');
const options = useCascaderAreaData();
const onFinish = ({ selectedOptions }) => {
    show.value = false;
    fieldValue.value = selectedOptions[1].text;
    if (fieldValue.value !== '全部') {
        const items = [];
        clonedatalist.newdatalist.forEach((item) => {
            if (item.area.includes(fieldValue.value)) {
                items.push(item);
            }
        })
        if (items.length) {
            dataList.newdatalist = items;
            towclonedatalist.newdatalist = items;
        } else {
            dataList.newdatalist = [];
            towclonedatalist.newdatalist = [];
        }
    }

};

const value1 = ref('');
// // 打开地图事件
// const OpenDitu = () => {
//     uni.getLocation({
//         geocode: true,
//         type: 'wgs84',
//         success: (res) => {
//             console.log(res, '获取当前位置')
//             uni.chooseLocation({
//                 longitude: res.longitude,
//                 latitude: res.latitude
//             })
//         },
//         address: (res) => {
//             console.log('address', res)
//         }
//     })
// }

const Search = () => {
    console.log('点击了搜素按钮');
}
</script>
  
<style scoped lang="scss">
.box {
    width: 100vw;
    height: auto;
    overflow: scroll;

    nav {
        width: 100%;
        height: 50px;
        display: flex;
        justify-content: space-around;
        align-items: center;

        .left {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 80px;
            height: 100%;

            select {
                width: 80%;
                height: 60%;
                border: none;
            }
        }

        .con {
            width: 230px;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;

            .van-cell {
                display: flex;
                width: 90%;
                height: 40px;
                background: #F4F4F4;
                border-radius: 5px;

            }
        }

        .right {
            flex: 1;
        }
    }

    header {
        width: 100%;
        height: 100px;
        display: flex;
        align-items: center;

        .Top-con {
            width: 100%;
            height: 50%;
            display: flex;
            font-size: 12px;

            .Top-con-item {
                width: 50%;
                height: 100%;
                display: flex;
                flex-direction: column;
                justify-content: center;
                align-items: center;

                .on {
                    color: red;
                }

                img {
                    width: 45%;
                    height: 90%;
                }
            }

        }
    }

    .box-con {
        width: 100%;
        min-height: 400px;

        .con {
            width: 95%;
            height: 100%;
            margin: 0 auto;

            .con-item {
                width: 100%;
                height: 115px;
                margin-top: 10px;
                margin-bottom: 15px;
                display: flex;
                justify-content: space-around;

                .con-item-left {
                    width: 30%;
                    height: 100%;
                    overflow: hidden;

                    .img {
                        width: 98%;
                        height: 98%;
                        display: inline-block;
                        margin: 0 auto;
                        border-radius: 5px;
                    }
                }

                .con-item-right {
                    width: 65%;
                    height: 100%;
                    display: flex;
                    flex-direction: column;
                    justify-content: space-between;

                    .title {
                        font-weight: bold;
                        font-size: 19px;
                    }

                    .pingmi {
                        font-size: 15px;
                    }

                    .jiage {
                        font-size: 14px;

                        .price {
                            font-weight: bold;
                            color: #FF9900;
                        }

                        .mi {
                            display: inline-block;
                            margin-left: 10px;
                            font-size: 13px;
                        }
                    }

                    .type {
                        width: 50px;
                        height: 25px;
                        background: #ccc;
                        font-size: 12px;
                        display: flex;
                        align-items: center;
                        justify-content: center;
                    }
                }

            }
        }
    }

    .null {
        width: 100%;
        height: 350px;
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        align-items: center;
        font-family: 'Courier New', Courier, monospace;

        img {
            width: 100%;
        }

        span {
            font-size: 19px;
        }
    }
}
</style>
  